package com.zhkj.txg.module.product.ui

import android.app.Activity
import android.content.Intent
import android.view.View
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import com.zhkj.lib.base.BaseActivity
import com.zhkj.txg.R
import kotlinx.android.synthetic.main.activity_product_comment.*

class ProductCommentListActivity : BaseActivity() {

    companion object {
        private val GOODS_ID = "goodsId"
        fun open(activity: Activity, goodsId: Long) {
            val intent = Intent(activity, ProductCommentListActivity::class.java)
                .putExtra(GOODS_ID, goodsId)
            activity.startActivity(intent)
        }
    }

    override fun statusTitleBar(): View? = titleCommentList
    override val layoutResId: Int = R.layout.activity_product_comment

    override fun initUI() {
        with(vpCommentList) {
            adapter = object : FragmentStateAdapter(this@ProductCommentListActivity) {
                override fun getItemCount(): Int = 4
                override fun createFragment(position: Int): Fragment = CommentListFragment.newInstance(
                    intent.getLongExtra(GOODS_ID, 0), position
                )
            }
            getChildAt(0)?.overScrollMode = View.OVER_SCROLL_NEVER
        }
        TabLayoutMediator(tabCommentList, vpCommentList, TabLayoutMediator.TabConfigurationStrategy { tab, position ->
            tab.customView = layoutInflater.inflate(R.layout.item_collect_goods, null).apply {
                findViewById<TextView>(R.id.tvGoods).text = when (position) {
                    1 -> getString(R.string.evaluate_good)
                    2 -> getString(R.string.evaluate_middle)
                    3 -> getString(R.string.evaluate_bad)
                    else -> getString(R.string.all)
                }
            }
        }).attach()
    }
}